package com.tanhua.server.controller;

import com.tanhua.model.dto.CommentDto;
import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author wjs
 * @version 1.0
 * @date 2021/12/28 0028 下午 2:39
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    /**
     * 分页查询评论列表
     * @param page
     * @param pagesize
     * @param movementId
     * @return
     */
    @GetMapping
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pagesize,String movementId) {
        PageResult pageResult = commentsService.findComments(movementId,page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 发布评论
     * @param commentDto
     * @return
     */
    @PostMapping
    public ResponseEntity saveComments(@RequestBody CommentDto commentDto){
        commentsService.saveComments(commentDto);
        return ResponseEntity.ok(null);
    }

    /**
     * 评论-点赞
     * @param id
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable String id){
        Integer count = commentsService.addLike(id);
        return ResponseEntity.ok(count);
    }
}
